import { createRouter, createWebHistory } from 'vue-router'
import HomePage from '../views/HomePage.jsx'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: HomePage,
    meta: { title: '药知晓' }
  },
  {
    path: '/catalog/:catalogId',
    name: 'CatalogList',
    component: () => import('../views/CatalogList.jsx'),
    meta: { title: '药知晓' }
  },
  {
    path: '/search',
    name: 'Search',
    component: () => import('../views/SearchPage.jsx'),
    meta: { title: '药知晓' }
  },
  // {
  //   path: '/pdfViewer',
  //   name: 'PdfViewer',
  //   component: () => import('../views/PdfViewer.jsx'),
  //   meta: { title: '药知晓' }
  // },
  // {
  //   path: '/pdfPreview',
  //   name: 'PdfPreview',
  //   component: () => import('../views/PdfPreview.jsx'),
  //   meta: { title: '药知晓' }
  // },
  {
    path: '/pdfRender',
    name: 'PdfRender',
    component: () => import('../views/PdfRender.jsx'),
    meta: { title: '药知晓' }
  },
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫 - 设置页面标题
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router
